import 'package:flutter/material.dart';
import 'package:flutter_yres/tool/constant.dart';
import 'package:flutter_yres/pages/user/login_pwd_page.dart';
import 'package:flutter_yres/pages/user/pay_pwd_page.dart';
import 'package:flutter_yres/pages/user/chage_phone_page.dart';
import 'package:flutter_yres/pages/user/card_list_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class SetPage extends StatefulWidget {
  SetPage({Key key}) : super(key: key);

  @override
  _SetPageState createState() => _SetPageState();
}

class _SetPageState extends State<SetPage> {
  bool value = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('设置'),
        ),
        body: LayoutBuilder(
          builder: (context, constraint) {
            return SingleChildScrollView(
              child: ConstrainedBox(
                constraints: BoxConstraints(minHeight: constraint.maxHeight),
                child: IntrinsicHeight(
                  child: Column(
                    children: <Widget>[
                      _creatCell(context, '登录密码', Text(' > '), ScreenUtil.getInstance().setWidth(20)),
                      _creatCell(context, '支付密码', Text('未设置' + ' > '), 1),
                      _creatCell(context, '手机号码', Text('111111' + ' > '), 1),
                      _creatCell(context, '银行卡', Text('未绑定' + ' > '), 1),
                      _creatCell(
                          context,
                          '消息通知',
                          Switch(value: this.value, onChanged: (bool val) {}),
                          ScreenUtil.getInstance().setWidth(28)),
                      _creatCell(context, '软件版本', Text(''), 1),
                      _creatCell(context, '清除缓存', Text('清除缓存'), 1),

                      
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Expanded(
                              child: Container(
                                  height: ScreenUtil.getInstance().setHeight(1334) * 0.06,
                                  margin: EdgeInsets.fromLTRB(
                                      ScreenUtil.getInstance().setWidth(28), ScreenUtil.getInstance().setWidth(28) * 2, ScreenUtil.getInstance().setWidth(28), 0),
                                  child: RaisedButton(
                                    shape: RoundedRectangleBorder(
                                      borderRadius:
                                          BorderRadius.all(Radius.circular(10)),
                                    ),
                                    //当前选中
                                    color: Colors.red,
                                    onPressed: () {
                                      Navigator.of(context).pushNamed('login');
                                    },
                                    child: Text(
                                      '退出登录',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  )))
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            );
          },
        ));
  }

  Widget _creatCell(
      BuildContext context, String title, Widget content, double top) {
    return GestureDetector(
        child: Container(
          color: Colors.white,
          height: ScreenUtil.getInstance().setWidth(28) * 3,
          margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), top, ScreenUtil.getInstance().setWidth(20), 1),
          child: Row(
            children: <Widget>[
              Expanded(
                  flex: 3,
                  child: Container(
                    margin: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(28)),
                    child: Text(title),
                  )),
              Expanded(
                flex: 1,
                child:
                    Container(alignment: Alignment.centerRight, child: content),
              )
            ],
          ),
        ),
        onTap: () {
          if (title == '登录密码') {
            Navigator.push(
                context,
                MaterialPageRoute(
                    //导航打开新视图
                    builder: (context) => LoginPwdPage()));
          }
          if (title == '支付密码') {
            Navigator.push(
                context,
                MaterialPageRoute(
                    //导航打开新视图
                    builder: (context) => PayPwdPage()));
          }
          if (title == '手机号码') {
            Navigator.push(
                context,
                MaterialPageRoute(
                    //导航打开新视图
                    builder: (context) => ChangePhonePage()));
          }
          if (title == '银行卡') {
            Navigator.push(
                context,
                MaterialPageRoute(
                    //导航打开新视图
                    builder: (context) => CardListPage()));
          }

          if (title == '清除缓存') {}
        });
  }
}
